/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.httpclient.URLUtil;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.admin.message.GetAccountInfoRequest;
/*     */ import com.zimbra.soap.type.AccountBy;
/*     */ import com.zimbra.soap.type.AccountSelector;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetAccountInfo
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public boolean domainAuthSufficient(Map context)
/*     */   {
/*  52 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean defendsAgainstDelegateAdminAccountHarvesting()
/*     */   {
/*  60 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  68 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*     */     
/*  70 */     GetAccountInfoRequest req = (GetAccountInfoRequest)JaxbUtil.elementToJaxb(request);
/*  71 */     Key.AccountBy accountBy = req.getAccount().getBy().toKeyAccountBy();
/*  72 */     String accountSelectorKey = req.getAccount().getKey();
/*     */     
/*  74 */     Provisioning prov = Provisioning.getInstance();
/*  75 */     Account account = prov.get(accountBy, accountSelectorKey, zsc.getAuthToken());
/*  76 */     defendAgainstAccountOrCalendarResourceHarvesting(account, accountBy, accountSelectorKey, zsc, Rights.Admin.R_getAccountInfo, Rights.Admin.R_getCalendarResourceInfo);
/*     */     
/*  78 */     Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_INFO_RESPONSE);
/*  79 */     response.addNonUniqueElement("name").setText(account.getName());
/*  80 */     addAttr(response, "zimbraId", account.getId());
/*  81 */     addAttr(response, "zimbraMailHost", account.getAttr("zimbraMailHost"));
/*     */     
/*  83 */     doCos(account, response);
/*  84 */     addUrls(response, account);
/*     */     
/*  86 */     return response;
/*     */   }
/*     */   
/*     */   static void addUrls(Element response, Account account) throws ServiceException
/*     */   {
/*  91 */     Server server = Provisioning.getInstance().getServer(account);
/*  92 */     if (server == null) return;
/*  93 */     String hostname = server.getAttr("zimbraServiceHostname");
/*  94 */     if (hostname == null) { return;
/*     */     }
/*  96 */     String http = URLUtil.getSoapURL(server, false);
/*  97 */     String https = URLUtil.getSoapURL(server, true);
/*     */     
/*  99 */     if (http != null) {
/* 100 */       response.addNonUniqueElement("soapURL").setText(http);
/*     */     }
/* 102 */     if ((https != null) && (!https.equalsIgnoreCase(http))) {
/* 103 */       response.addNonUniqueElement("soapURL").setText(https);
/*     */     }
/* 105 */     String adminUrl = URLUtil.getAdminURL(server);
/* 106 */     if (adminUrl != null) {
/* 107 */       response.addNonUniqueElement("adminSoapURL").setText(adminUrl);
/*     */     }
/* 109 */     String webMailUrl = URLUtil.getPublicURLForDomain(server, Provisioning.getInstance().getDomain(account), "", true);
/* 110 */     if (webMailUrl != null) {
/* 111 */       response.addNonUniqueElement("publicMailURL").setText(webMailUrl);
/*     */     }
/*     */   }
/*     */   
/*     */   private static void addAttr(Element response, String name, String value) {
/* 116 */     if ((value != null) && (!value.equals(""))) {
/* 117 */       Element e = response.addNonUniqueElement("a");
/* 118 */       e.addAttribute("n", name);
/* 119 */       e.setText(value);
/*     */     }
/*     */   }
/*     */   
/*     */   static void doCos(Account acct, Element response) throws ServiceException {
/* 124 */     Cos cos = Provisioning.getInstance().getCOS(acct);
/* 125 */     if (cos != null) {
/* 126 */       Element eCos = response.addUniqueElement("cos");
/* 127 */       eCos.addAttribute("id", cos.getId());
/* 128 */       eCos.addAttribute("name", cos.getName());
/*     */     }
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 134 */     relatedRights.add(Rights.Admin.R_getAccountInfo);
/* 135 */     relatedRights.add(Rights.Admin.R_getCalendarResourceInfo);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetAccountInfo.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */